import openpyxl

from common.log.log import log


def read_data(filename, sheetname):
    wb = openpyxl.load_workbook(filename)  # 加载工作簿
    sheet = wb[sheetname]  # 获取表单
    max_raw = sheet.max_row + 1  # 获取最大行数
    # print(max_raw)
    case_list = []  # 创建空列表，存放测试用例
    for i in range(2, max_raw):
        dict1 = dict(
            case_id=sheet.cell(row=i, column=1).value,  # 获取case_id
            case_name=sheet.cell(row=i, column=3).value,  # 获取case_name
            method=sheet.cell(row=i, column=4).value,  # 获取method
            path=sheet.cell(row=i, column=5).value,  # path
            data=sheet.cell(row=i, column=6).value,  # data
            status_code=sheet.cell(row=i, column=7).value,  # 获取status_code
            check=sheet.cell(row=i, column=8).value  # 获取check
        )
        case_list.append(dict1)
    return case_list


if __name__ == '__main__':
    # case = read_data(r'D:\jinhuashop\common\excel\test_api_applets_basic_query_yc.xlsx', 'api')
    case = read_data(r"//TestCase/test_huawang_yk/test_ht_api/test_ht_qyery_api/test_yk_ht_query_api.xlsx", 'api')
    print(case)

    # for one  in case:
    #     print(one)
    # # log.info(case)
